package salary

// emp db
type EmpDB struct {
	Employees map[int]Employee
	Members   map[int]Employee
}

var empDB *EmpDB

// 获取db
func GetDB() *EmpDB {
	if empDB == nil {
		InitDB()
	}
	return empDB
}


// 初始化数据, 最先被调用
func InitDB() {
	empDB = &EmpDB{
		make(map[int]Employee),
		make(map[int]Employee),
	}
}

// 根据id查询员工
func (db *EmpDB) GetEmployee(id int) Employee {
	return db.Employees[id]
}

// 查询所有员工
func (db *EmpDB) GetAll() []Employee {
	employees := make([]Employee, len(empDB.Employees))
	for _, employee := range db.Employees {
		employees = append(employees, employee)
	}
	return employees
}

// 根据id删除
func (db *EmpDB) RemoveEmployee(id int) {
	delete(db.Employees, id)
}

// 添加员工
func (db *EmpDB) AddEmployee(employee Employee) {
	db.Employees[employee.EmployeeId] = employee
}

// 根据id查询Member
func (db *EmpDB) GetMember(memberId int) Employee {
	return db.Members[memberId]
}

// 添加工会隶属关系
func (db *EmpDB) AddUnionAffiliation(memberId int, employee Employee) {
	db.Members[memberId] = employee
}

// 删除工会隶属关系
func (db *EmpDB) removeUnionAffiliation(memberId int) {
	delete(db.Members, memberId)
}
